home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / MNetsrc.hqx / Mac TCP_IP Source v.33 / icmpdump.c < prev    next >
C/C++ Source or Header  |  1989-02-22  |  3KB  |  132 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "icmp.h"
  6. #include "trace.h"
  7.  
  8. #ifdef MAC
  9.     extern int tcptrcflg;
  10.     extern FILE *trcwndp;
  11. #endif
  12.  
  13. /* Dump an ICMP header */
  14. void
  15. icmp_dump(bpp,source,dest,check)
  16. struct mbuf **bpp;
  17. int32 source,dest;
  18. int check;        /* If 0, bypass checksum verify */
  19. {
  20.     struct icmp icmp;
  21.     int16 csum;
  22.  
  23.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  24.         return;
  25.     csum = cksum(NULLHEADER,*bpp,len_mbuf(*bpp));
  26.     
  27.     ntohicmp(&icmp,bpp);
  28.     
  29.     if(uchar(icmp.type) <= 16 && icmptypes[uchar(icmp.type)] != NULLCHAR)
  30. #ifdef MAC
  31.         fprintf(trcwndp,"ICMP: %s",icmptypes[uchar(icmp.type)]);
  32.     else
  33.         fprintf(trcwndp,"ICMP: type %u",uchar(icmp.type));
  34.  
  35.     switch(uchar(icmp.type)){
  36.     case DEST_UNREACH:
  37.         if(uchar(icmp.code) <= 5)
  38.             fprintf(trcwndp," %s",unreach[uchar(icmp.code)]);
  39.         else
  40.             fprintf(trcwndp," code %u",uchar(icmp.code));
  41.         break;
  42.     case REDIRECT:
  43.         if(uchar(icmp.code) <= 3)
  44.             fprintf(trcwndp," %s",redirect[uchar(icmp.code)]);
  45.         else
  46.             fprintf(trcwndp," code %u",uchar(icmp.code));
  47.         break;
  48.     case TIME_EXCEED:
  49.         if(uchar(icmp.code) <= 1)
  50.             fprintf(trcwndp," %s",exceed[uchar(icmp.code)]);
  51.         else
  52.             fprintf(trcwndp," code %u",uchar(icmp.code));
  53.         break;
  54.     case PARAM_PROB:
  55.         fprintf(trcwndp," pointer = %u",icmp.args.pointer);
  56.         break;
  57.     case ECHO:
  58.     case ECHO_REPLY:
  59.     case INFO_RQST:
  60.     case INFO_REPLY:
  61.     case TIMESTAMP:
  62.     case TIME_REPLY:
  63.         fprintf(trcwndp," id %u seq %u",icmp.args.echo.id,icmp.args.echo.seq);
  64.         break;
  65.     }
  66.     if(check && csum != 0){
  67.         fprintf(trcwndp," CHECKSUM ERROR (%u)",csum);
  68.     }
  69.     fprintf(trcwndp,"\n");
  70.     /* Dump the offending IP header, if any */
  71.     switch(icmp.type){
  72.     case DEST_UNREACH:
  73.     case TIME_EXCEED:
  74.     case PARAM_PROB:
  75.     case QUENCH:
  76.     case REDIRECT:
  77.         fprintf(trcwndp,"Returned ");
  78. #else
  79.         printf("ICMP: %s",icmptypes[uchar(icmp.type)]);
  80.     else
  81.         printf("ICMP: type %u",uchar(icmp.type));
  82.  
  83.     switch(uchar(icmp.type)){
  84.     case DEST_UNREACH:
  85.         if(uchar(icmp.code) <= 5)
  86.             printf(" %s",unreach[uchar(icmp.code)]);
  87.         else
  88.             printf(" code %u",uchar(icmp.code));
  89.         break;
  90.     case REDIRECT:
  91.         if(uchar(icmp.code) <= 3)
  92.             printf(" %s",redirect[uchar(icmp.code)]);
  93.         else
  94.             printf(" code %u",uchar(icmp.code));
  95.         break;
  96.     case TIME_EXCEED:
  97.         if(uchar(icmp.code) <= 1)
  98.             printf(" %s",exceed[uchar(icmp.code)]);
  99.         else
  100.             printf(" code %u",uchar(icmp.code));
  101.         break;
  102.     case PARAM_PROB:
  103.         printf(" pointer = %u",icmp.args.pointer);
  104.         break;
  105.     case ECHO:
  106.     case ECHO_REPLY:
  107.     case INFO_RQST:
  108.     case INFO_REPLY:
  109.     case TIMESTAMP:
  110.     case TIME_REPLY:
  111.         printf(" id %u seq %u",icmp.args.echo.id,icmp.args.echo.seq);
  112.         break;
  113.     }
  114.     if(check && csum != 0){
  115.         printf(" CHECKSUM ERROR (%u)",csum);
  116.     }
  117.     printf("\n");
  118.     /* Dump the offending IP header, if any */
  119.     switch(icmp.type){
  120.     case DEST_UNREACH:
  121.     case TIME_EXCEED:
  122.     case PARAM_PROB:
  123.     case QUENCH:
  124.     case REDIRECT:
  125.         printf("Returned ");
  126. #endif
  127.         ip_dump(bpp,0);
  128.     }
  129. }
  130.  
  131.  
  132.